package com.lk.demo.service;

import com.lk.demo.conf.MyConf;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

@Service
public class HelloService {

    @Value("${my.custom.prop1}")
    String myCustomProp1;

    @Value("${my.custom.prop2}")
    String myCustomProp2;

    @Value("${my.conf.prop1}")
    String myConfProp1;

    @Value("${my.conf.prop2}")
    String myConfProp2;

    @Value("${my.conf.more.m-prop1}")
    String myConfMoreProp1;


    @Autowired
    MyConf myConf;

    private static final Logger log = LoggerFactory.getLogger(HelloService.class);

    public Map<String, Object> getMyConfigByConfigClass() {
        Map<String, Object> props = new HashMap<>();
        props.put("my.conf.prop1", myConf.getProp1());
        props.put("my.conf.prop2", myConf.getProp2());
        props.put("my.conf.more.m-prop2", myConf.getMore().getMProp1());
        props.put("my.conf.more.m-prop1", myConf.getMore().getMProp2());
        log.info("getMyConfigByConfigClass:{}", props);
        return props;
    }

    public Map<String, Object> getMyConfigByValueAnnotation() {
        Map<String, Object> props = new HashMap<>();
        props.put("my.custom.prop1", myCustomProp1);
        props.put("my.custom.prop2", myCustomProp2);
        props.put("my.conf.prop1", myConfProp1);
        props.put("my.conf.prop2", myConfProp2);
        props.put("my.conf.more.m-prop1", myConfMoreProp1);
        log.debug("getMyConfigByValueAnnotation:{}", props);
        return props;
    }
}
